package com.camps.sdk.decrypt;

import com.camps.sdk.common.Constants;
import com.camps.sdk.entity.DeviceUpMessage;
import com.camps.sdk.entity.IccIdAndSimCard;
import com.camps.sdk.entity.LocationData;
import com.camps.sdk.utils.LocationUtils;

import java.util.List;

/**
 * @Author ldaoliang
 * @Date create in 15:58 2021/9/1
 * @Description
 */
public class AnalyzeIccId implements AnalyticalData {
    @Override
    public DeviceUpMessage parseData(String originalData) {
        //*TJ,2020916012,V4,GETICCID,130305,111111,86954789991234566958, 13612345678,A,2212.8745,N,11346.6574,E,14.28,028,220902,FFFFFFFF#
        //解密
        String[] split = parseCommand(originalData);
        String imei = split[1];
        String commandNumber = split[4];
        String deviceTime = split[5];
        String Iccid = split[6];
        String phone = split[7];
        String latitude = split[9];
        String longitude = split[11];
        String speed = split[13];
        String orientation = split[14];
        String deviceDate = split[15];
        String deviceStatus = split[16];
        IccIdAndSimCard iccIdAndSimCard = new IccIdAndSimCard();
        iccIdAndSimCard.setCommandNumber(commandNumber);
        iccIdAndSimCard.setDeviceDate(deviceDate);
        iccIdAndSimCard.setDeviceStatus(deviceStatus);
        iccIdAndSimCard.setDeviceTime(deviceTime);
        iccIdAndSimCard.setImei(imei);
        iccIdAndSimCard.setSimCard(phone);
        iccIdAndSimCard.setIccId(Iccid);
        LocationData mqLocationData = new LocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        List<Double> latlng = LocationUtils.transiformLatAndLng(longitude,latitude);
        mqLocationData.setLatitude(latlng.get(1));
        mqLocationData.setLongitude(latlng.get(0));
        iccIdAndSimCard.setLocationData(mqLocationData);
        return structureMessage(Constants.REPLY,Constants.CMD_GET_ICCID,false,"",iccIdAndSimCard);
    }
}
